# -*- encoding:utf-8 -*-
"""
@作者：ven
@文件名：common.py
@时间：2022-11-08  14:09
@文档说明:
"""
import base64

from faker import Faker

f = Faker(locale='zh_CN')

def crc16(x, invert):
    wCRCin = 0xFFFF
    wCPoly = 0x8408
    for byte in x:

        wCRCin = wCRCin^(byte&0xFF)

        for i in range(8):
            if wCRCin & 0x0001 ==1:
                wCRCin = (wCRCin >> 1) ^ wCPoly
            else:
                wCRCin = (wCRCin >> 1)


    s = hex(wCRCin).upper()

    return s[-2:] + s[-4:-2] if invert == True else s[-4:-2] + s[-2:]


def imageToBase64(filePath):
    with open(filePath, "rb") as f:  # 转为二进制格式
        base64_data = str(base64.b64encode(f.read()), 'utf-8')  # 使用base64进行加密
        return base64_data  # 输出格式b'xxxx', base64_data = str(base64.b64encode(f.read()), 'utf-8') 输出不包含b


if __name__ == '__main__':

    s ='1D00EE005AA301395AD1239317C2010C3A299044102919950815000B4119'
    s1='E2002021102919950815000C'
    S2='3A299044102919950815000B'
    var = bytearray.fromhex("1D00EE005AA301395AD1239317C2010CB20020211029199508150010DDA7")  # 将hexstring 转化为 字节数组。
    print(crc16(var,True))
